﻿namespace Harness.Commands
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;

    internal class ResizeCommand : ICommand
    {
        #region Constants

        private const int WidthArgIndex = 0;

        private const int HeightArgIndex = 1;

        #endregion

        #region Public Methods

        public void SyntaxCheck(IHarness harness, IEnumerable<object> args)
        {
            int w;

            if (!int.TryParse((args.ElementAtOrDefault(WidthArgIndex) ?? string.Empty).ToString(), out w))
            {
                throw new ArgumentOutOfRangeException((WidthArgIndex + 1).ToString() + ":Width");
            }

            int h;

            if (!int.TryParse((args.ElementAtOrDefault(HeightArgIndex) ?? string.Empty).ToString(), out h))
            {
                throw new ArgumentOutOfRangeException((HeightArgIndex + 1).ToString() + ":Height");
            }
        }

        public dynamic Execute(IHarness harness, IEnumerable<object> args)
        {
            int w = int.Parse((args.ElementAtOrDefault(WidthArgIndex) ?? string.Empty).ToString());
            int h = int.Parse((args.ElementAtOrDefault(HeightArgIndex) ?? string.Empty).ToString());

            IE.SetWindowSize(w, h);

            return null;
        }

        #endregion
    }
}
